unit oEditorLEManager;

interface

uses
  oManager, oProcessItem, oProcessObjects, oProcessObjectConstants,
  oFormObjectInspector, oTurniquet, oLogicalEntity;

type
  TEditorLEManager = class(TManager)
    strict private
      aEntity: TLogicalEntity;
      aForm: TformObjectInspector;
      procedure fillTourniquetForm(paEntity: TTurniquet);
    public
      constructor create(paMaster: TManager);
      function ProcessObject(paItem: TProcessItem): TProcessItem; override;
  end;

implementation

uses
  SysUtils, Dialogs, oEntityTypeConstants;

resourcestring edlemannotvalidtype = 'not valid type';
resourcestring entityTourniquetEN = 'TOURNIQUET';

{ TEditorLEManager }

constructor TEditorLEManager.create(paMaster: TManager);
begin
  inherited create(paMaster);
  aForm := nil;
  aEntity := nil;
end;

procedure TEditorLEManager.fillTourniquetForm(paEntity: TTurniquet);
begin
  aEntity := paEntity;
  with  aForm.frameObjectInspector do
    begin
      showTourniquet;
      txtGenerator.Text := paEntity.GeneratorData.toString;
      Entity := paEntity;
      lblType.Caption := entityTourniquetEN;
    end;
end;

function TEditorLEManager.ProcessObject(paItem: TProcessItem): TProcessItem;
begin

  with paItem.Data as TProcessingLogicalEntity do
  case paItem.Code of

    PO_EDLEMAN_EDIT:
    begin
      if not(paItem.Data is TProcessingLogicalEntity) then raise Exception.Create(edlemannotvalidtype);
      case EntityType of

        ET_TURNIQUET_TYPE:
        begin
          fillTourniquetForm((paItem.Data as TProcessingLogicalEntity).Entity as TTurniquet);
        end

        else MessageDlg('coming soon for entity type: ' + IntToStr(EntityType),mtInformation,[mbOK],0);
      end;

      result := nil;
    end;

    PO_EDLEMAN_SHOW:
    begin
      if aForm <> nil then aForm.Free;
      aForm := TformObjectInspector.Create(nil);
      aForm.Show;
      result := nil;
      aEntity := nil;
    end;

    PO_EDLEMAN_HIDE:
    begin
      FreeAndNil(aForm);
      result := nil;
      aEntity := nil;
    end;

  end;

end;

end.
